package com.jha.develop.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jha.common.annotation.Log;
import com.jha.common.core.controller.BaseController;
import com.jha.common.core.domain.AjaxResult;
import com.jha.common.enums.BusinessType;
import com.jha.develop.domain.vo.SysStudentVo;
import com.jha.develop.domain.bo.SysStudentBo;
import com.jha.develop.domain.SysStudent;
import com.jha.develop.service.ISysStudentService;
import com.jha.common.utils.poi.ExcelUtil;
import com.jha.common.core.page.TableDataInfo;

/**
 * 学生信息Controller
 *
 * @author JHA
 * @date 2025-11-13
 */
@RestController
@RequestMapping("/develop/student" )
public class SysStudentController extends BaseController {
    @Autowired
    private ISysStudentService sysStudentService;

    /**
     * 查询学生信息列表
     */
    @PreAuthorize("@ss.hasPermi('develop:student:pageList')" )
    @GetMapping("/pageList" )
    public TableDataInfo pageList(SysStudentBo bo) {
        startPage();
        List<SysStudentVo> list = sysStudentService.queryList(bo);
        return getDataTable(list);
    }
    /**
     * 查询学生信息列表(不分页)
     */
    @PreAuthorize("@ss.hasPermi('develop:student:list')" )
    @GetMapping("/list" )
    public AjaxResult list(SysStudentBo bo) {
        List<SysStudentVo> list = sysStudentService.queryList(bo);
        return AjaxResult.success(list);
    }

    /**
     * 导出学生信息列表
     */
    @PreAuthorize("@ss.hasPermi('develop:student:export')" )
    @Log(title = "学生信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, SysStudentBo bo) {
        List<SysStudentVo> list = sysStudentService.queryList(bo);
        ExcelUtil<SysStudentVo> util = new ExcelUtil<SysStudentVo>(SysStudentVo.class);
        util.exportExcel(response, list, "学生信息数据" );
    }

    /**
     * 获取学生信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:student:query')" )
    @GetMapping(value = "/{studentId}" )
    public AjaxResult getInfo(@PathVariable("studentId" ) Long studentId) {
        return success(sysStudentService.queryById(studentId));
    }

    /**
     * 新增学生信息
     */
    @PreAuthorize("@ss.hasPermi('develop:student:add')" )
    @Log(title = "学生信息" , businessType = BusinessType.INSERT)
    @PostMapping("/add" )
    public AjaxResult add(@RequestBody SysStudentBo bo) {
        return toAjax(sysStudentService.insertByBo(bo));
    }

    /**
     * 修改学生信息
     */
    @PreAuthorize("@ss.hasPermi('develop:student:edit')" )
    @Log(title = "学生信息" , businessType = BusinessType.UPDATE)
    @PutMapping("/edit" )
    public AjaxResult edit(@RequestBody SysStudentBo bo) {
        return toAjax(sysStudentService.updateByBo(bo));
    }

    /**
     * 删除学生信息
     */
    @PreAuthorize("@ss.hasPermi('develop:student:remove')" )
    @Log(title = "学生信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{studentIds}" )
    public AjaxResult remove(@PathVariable Long[] studentIds) {
        return toAjax(sysStudentService.deleteWithValidByIds(Arrays.asList(studentIds), true));
    }
}
